package com.example.controller;

import com.example.entity.CommonResult;
import com.example.service.AccountService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.math.BigDecimal;

/**
 * @author: 21050134
 * @date: 2023/10/30 16:41
 * @description:
 */
@RestController
@Slf4j
public class AccountController {
	@Resource
	private AccountService accountService;

	@Value("${server.port}")
	private String serverPort;

	@PostMapping(value = "/account/decrease")
	public CommonResult decrease(@RequestParam("userId") Long userId, @RequestParam("money") BigDecimal money){
		int decrease = accountService.decrease(userId,money);
		CommonResult result;
		if(decrease > 0){
			result = new CommonResult(200,"from mysql,serverPort: " + serverPort,decrease);
		}else{
			result = new CommonResult(505,"from mysql,serverPort: " + serverPort,"账户扣减失败");
		}
		return result;
	}

}
